﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://wpfimageviewer.codeplex.com
using System;
using System.Windows;
using ImageAppViewModels;
using BrainTechLLC.WPF;
using Stats.Plugin;
using WpfImageDuplicates;
using BrainTechLLC;

namespace Stats.Plugin
{
    public class StatsWindowHandler : WindowHandlerBase<StatsWindow, Window>, IStatsWindowHandler
    {
        public static PluginDefinitionLoaded<IStatsWindowHandler> Handler; 
        protected ThumbnailCollectionStatsViewModel _thumbStatsViewModel;

        public StatsWindowHandler(Window1 parentWindow, PluginDefinitionLoaded<IStatsWindowHandler> handler)
            : base(parentWindow)
        {
            Handler = handler;
            _parentWindow = parentWindow;
        }

        public override void OpenWindow(Window owner)
        {
            if (_thumbStatsViewModel == null)
            {
                _thumbStatsViewModel = new ThumbnailCollectionStatsViewModel(Window1.MainWindow.CollectionViews[0].ThumbsHandler);
            }

            if (_window == null)
            {
                _window = new StatsWindow();// { Owner = owner };
                _window.DataContext = (_parentWindow as Window1).FileImageCollectionViewModels[0].Stats;
                _window.ThumbnailCollectionStatsViewModel = _thumbStatsViewModel;
                _window.Closed += new EventHandler(_window_Closed);
                _window.Show();
                _window.MakeTopmost();
            }

            _window.Show();
            _window.Focus();
        }

        private void _window_Closed(object sender, EventArgs e)
        {
            _window.Closed -= _window_Closed;
            _window = null;
        }


    }
}
